" 语法高亮
syntax on   
" 在行和段开始处使用制表符
set smarttab
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
 " 显示行号
set nu
" 打开状态栏标尺
set ruler
" 编码设置
set enc=utf-8
" 自动缩进
set autoindent
" 不要用空格代替制表符
set noexpandtab
" 禁止生成临时文件
set nobackup
" 搜索忽略大小写
set ignorecase

autocmd BufNewFile *.py,*.c,*.cpp,*.cxx,*.cc,*.java,*.sh exec ":call Init()"
func Init()
	
	if &filetype == 'python'
		call setline(1,"#!/usr/bin/env python3.5")
		call append(line("."),"# -*- coding: utf-8 -*-")
		call append(line(".")+1,"")
		call append(line(".")+2,"#**********************************")
		call append(line(".")+3,"")
		call append(line(".")+4,"#	>	Author: SuperDian")	
		call append(line(".")+5,"#	>	Mail: tech-sky@outlook.com")
		call append(line(".")+6,"#	>	Create Time: ".strftime("%c"))
		call append(line(".")+7,"#	>	File Name: ".expand("%"))
		call append(line(".")+8,"")
		call append(line(".")+9,"#*****************************")
		call append(line(".")+10,"")
		call append(line(".")+11,"")
	endif
	if &filetype == 'c'
		call setline(1,"/***********************************************")
		call append(line("."),"")
		call append(line(".")+1,"")
		call append(line(".")+2,"	>	Author: SuperDian")	
		call append(line(".")+3,"	>	Mail: tech-sky@outlook.com")
		call append(line(".")+4,"	>	Create Time: ".strftime("%c"))
		call append(line(".")+5,"	>	File Name: ".expand("%"))
		call append(line(".")+6,"")
		call append(line(".")+7,"***********************************************/")
		call append(line(".")+8,"")
		call append(line(".")+9,"#include<stdio.h>")
		call append(line(".")+10,"#include<string.h>")
		call append(line(".")+11,"")
		call append(line(".")+12,"int main()")
		call append(line(".")+13,"{")
		call append(line(".")+14,"")
		call append(line(".")+15,"	return 0;")
		call append(line(".")+16,"}")
		call append(line(".")+17,"")
		call append(line(".")+18,"")
	endif

	if &filetype == 'cpp'
		call setline(1,"/***********************************************")
		call append(line("."),"")
		call append(line(".")+1,"")
		call append(line(".")+2,"	>	Author: SuperDian")	
		call append(line(".")+3,"	>	Mail: tech-sky@outlook.com")
		call append(line(".")+4,"	>	Create Time: ".strftime("%c"))
		call append(line(".")+5,"	>	File Name: ".expand("%"))
		call append(line(".")+6,"")
		call append(line(".")+7,"***********************************************/")
		call append(line(".")+8,"#include<bits/stdc++.h>")
		call append(line(".")+9,"")
		call append(line(".")+10,"using namespace std;")
		call append(line(".")+11,"")
		call append(line(".")+12,"int main()")
		call append(line(".")+13,"{")
		call append(line(".")+14,"")
		call append(line(".")+15,"	return 0;")
		call append(line(".")+16,"}")
		call append(line(".")+17,"")
	endif
		
	if &filetype == 'java'
		call setline(1,"/* **********************************************")
		call append(line("."),	"")
		call append(line(".")+1,	"")
		call append(line(".")+2,	"	>	Author: SuperDian")	
		call append(line(".")+3,	"	>	Mail: tech-sky@outlook.com")
		call append(line(".")+4,	"	>	Create Time: ".strftime("%c"))
		call append(line(".")+5,	"	>	File Name: ".expand("%"))
		call append(line(".")+6,	"")
		call append(line(".")+7,	"********************************************** */")
		call append(line(".")+8, 	"")
		call append(line(".")+9, 	"public class ".expand("%<")."{")
		call append(line(".")+10, 	"	public static void main(String[] args){")
		call append(line(".")+11, 	"")
		call append(line(".")+12, 	"	}")
		call append(line(".")+13,	"}")
	endif
	if &filetype == 'sh'
		call setline(1,"\#!/bin/bash")
	    call append(line("."),	 "\#**************************************************") 
		call append(line(".")+1,	 "\#	>	 Author: SuperDian") 
		call append(line(".")+2, "\#	>	 mail: tech-sky@outlook.com") 
		call append(line(".")+3, "\#	>	 Created Time: ".strftime("%c")) 
		call append(line(".")+4, "\#	>	 File Name: ".expand("%")) 
		call append(line(".")+5, "\#**************************************************") 
		call append(line(".")+6, "") 
		call append(line(".")+7, "")
		call append(line(".")+8, "")
	endif
	normal G
endfunc
map <F9> :call Run()<CR>
func Run()
	
	silent exec "w"
	let w:hello = ""
	if &filetype == 'c'
		silent :exec "!gcc % -o %<.o"
		exec "!./%<.o"
	endif
	if &filetype == 'cpp'
		silent exec "!g++ % -o %<.o -std=c++14"
		exec "!./%<.o"
	endif
	if &filetype == 'java'
		silent exec "!javac %"
		exec "!java %<"
	endif
	if &filetype == 'python'
		silent exec "!chmod a+x %"
		exec "!./%"
	endif
	if &filetype == 'sh'
		exec "!chmod a+x %"
		exec "!./%"
	endif
endfunc
